package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain .GxTempStatement;
import com.ruoyi.system.service.IGxTempStatementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模板语句Controller
 * 
 * @author lsn
 * @date 2023-01-14
 */
@RestController
@RequestMapping("/system/statement")
public class GxTempStatementController extends BaseController
{
    @Autowired
    private IGxTempStatementService gxTempStatementService;

    /**
     * 查询模板语句列表
     */
    @GetMapping("/list")
    public TableDataInfo list(GxTempStatement gxTempStatement)
    {
        startPage();
        List<GxTempStatement> list = gxTempStatementService.selectGxTempStatementList(gxTempStatement);
        return getDataTable(list);
    }

    @GetMapping("/listByUser")
    public TableDataInfo listByUser(GxTempStatement gxTempStatement)
    {
        startPage();
        List<GxTempStatement> list = gxTempStatementService.selectGxTempStatementListByUser(gxTempStatement);
        return getDataTable(list);
    }

    @GetMapping("/listByDept")
    public TableDataInfo listByDept(GxTempStatement gxTempStatement)
    {
        startPage();
        List<GxTempStatement> list = gxTempStatementService.selectGxTempStatementListByDept(gxTempStatement);
        return getDataTable(list);
    }

    /**
     * 导出模板语句列表
     */
    @Log(title = "模板语句", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxTempStatement gxTempStatement)
    {
        List<GxTempStatement> list = gxTempStatementService.selectGxTempStatementList(gxTempStatement);
        ExcelUtil<GxTempStatement> util = new ExcelUtil<GxTempStatement>(GxTempStatement.class);
        util.exportExcel(response, list, "模板语句数据");
    }

    /**
     * 获取模板语句详细信息
     */
    @GetMapping(value = "/{tempId}")
    public AjaxResult getInfo(@PathVariable("tempId") Long tempId)
    {
        return AjaxResult.success(gxTempStatementService.selectGxTempStatementByTempId(tempId));
    }

    /**
     * 新增模板语句
     */
    @Log(title = "模板语句", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GxTempStatement gxTempStatement)
    {
        return toAjax(gxTempStatementService.insertGxTempStatement(gxTempStatement));
    }

    /**
     * 修改模板语句
     */
    @Log(title = "模板语句", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GxTempStatement gxTempStatement)
    {
        return toAjax(gxTempStatementService.updateGxTempStatement(gxTempStatement));
    }

    /**
     * 删除模板语句
     */
    @Log(title = "模板语句", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tempIds}")
    public AjaxResult remove(@PathVariable Long[] tempIds)
    {
        return toAjax(gxTempStatementService.deleteGxTempStatementByTempIds(tempIds));
    }
}
